function cookiesDel(name) {
    chrome.cookies.remove({
        "url": "https://www.baidu.com/*",
        "name": name
    }, function(result){
        console.log("cookie Removed");
    });
}

function cookieDelAll() {
    chrome.storage.sync.get({trackBlock: 'off'}, function (items) {
        if (items.trackBlock == "on") {
            console.log("cookie called");

            chrome.cookies.getAll({url: 'https://www.baidu.com/*'}, function(cookies){
                var currentC;
                for(var i=0; i<cookies.length; i++) {
                    currentC = cookies[i];
                    cookiesDel(currentC.name);
                }
            });
            console.log(items.trackBlock);

        }})

}



chrome.webRequest.onBeforeRequest.addListener(
    function(details) { return {cancel: true}; },
    {urls: ["*://sp0.baidu.com/*"]},
    ["blocking"]);

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        console.log(sender.tab ?
            "from a content script:" + sender.tab.url :
            "from the extension");
        if (request.greeting == "cleanCookies")
            cookieDelAll();

        sendResponse({farewell: "goodbye"});
    });

setInterval(function(){
    cookieDelAll();
},60000);